﻿Imports System
Imports System.IO
Imports System.Text
Imports System.Configuration
Imports System.Data.SqlClient
Imports System.Threading


Public Class PushThreadManager
    Private m_thMain As System.Threading.Thread
    Private m_booMustStop As Boolean

    ''' <summary>
    ''' Stops the currently running thread.
    ''' </summary>
    ''' <remarks>This method stops the currently running thread by setting a stop value.</remarks>
    Public Sub StopWork()
        m_booMustStop = True
        If Not m_thMain Is Nothing Then
            If Not m_thMain.Join(100) Then
                m_thMain.Abort()
            End If
        End If
    End Sub

    ''' <summary>
    ''' Begins the process of collecting data to pass to the cURLPush class.
    ''' </summary>
    ''' <param name="arylstDoWorkArgs"></param>
    ''' <remarks>This thread is started from the Worker class thread and multiple instances of these 'children' may be present at any given time.</remarks>
    Public Sub DoWork(ByVal arylstDoWorkArgs As Object)
        m_thMain = System.Threading.Thread.CurrentThread

        Dim objcURL As New cURLPush(arylstDoWorkArgs(0).ToString())

        Try
            'Move the string into a memory stream and send it to the push method 
            objcURL.Curl2Hub()

        Catch ex As Exception
            System.Diagnostics.EventLog.WriteEntry("VOEIS Hub Push Service", "Error in PushThreadManager class - DoWork method." & Environment.NewLine & ex.Message.ToString, EventLogEntryType.Error)
            Dim mailer As New SendMail()
            mailer.SendServiceMail("VOEIS Hub Push Service - Error", "Error in PushThreadManager class - DoWork method." & Environment.NewLine & ex.Message.ToString)
        Finally
            'Signal to the parent thread that we are done here
            CType(arylstDoWorkArgs(1), ManualResetEvent).Set()
        End Try
    End Sub

End Class
